//
//  WHAccountInfo.m
//  GoldenManager
//
//  Created by 文 on 2018/7/13.
//  Copyright © 2018年 sanpu. All rights reserved.
//

#import "WHAccountInfo.h"
//#import "JKCategories.h"
#import "NSDictionary+NSArray+Addition.h"
#import "WHPickerAddressModel.h"

// 单例宏
#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
\
static classname *shared##classname = nil; \
\
+ (classname *)shared##classname \
{ \
@synchronized(self) \
{ \
if (shared##classname == nil) \
{ \
shared##classname = [[self alloc] init]; \
} \
} \
\
return shared##classname; \
} \
\
+ (id)allocWithZone:(NSZone *)zone \
{ \
@synchronized(self) \
{ \
if (shared##classname == nil) \
{ \
shared##classname = [super allocWithZone:zone]; \
return shared##classname; \
} \
} \
\
return nil; \
} \
\
- (id)copyWithZone:(NSZone *)zone \
{ \
return self; \
}


@implementation WHAccountInfo

SYNTHESIZE_SINGLETON_FOR_CLASS(WHAccountInfo)

- (void)updateAccountMessgage:(NSDictionary *)userCenterDictionary{
    self.userName            = [userCenterDictionary stringValueForKey:@"userName"];
    self.businessWechat      = [userCenterDictionary stringValueForKey:@"businessWechat"];
    self.headPortrait        = [userCenterDictionary stringValueForKey:@"headPortrait"];
    self.appOpenId           = [userCenterDictionary stringValueForKey:@"appOpenId"];
    self.levelId             = [userCenterDictionary stringValueForKey:@"levelId"];
    self.vipLevel            = [userCenterDictionary stringValueForKey:@"vipLevel"];
    self.levelImagePath      = [userCenterDictionary stringValueForKey:@"levelImagePath"];
    self.levelName           = [userCenterDictionary stringValueForKey:@"levelName"];
    self.nickName            = [userCenterDictionary stringValueForKey:@"nickName"];
    self.wechatNickName      = [userCenterDictionary stringValueForKey:@"nickName"];
    self.registerDate        = [userCenterDictionary stringValueForKey:@"registerDate"];
    self.shareCode           = [userCenterDictionary stringValueForKey:@"shareCode"];
    self.upUserName          = [userCenterDictionary stringValueForKey:@"upUserName"];
    self.userCode            = [userCenterDictionary stringValueForKey:@"userCode"];
    
    self.isPartner           = [[userCenterDictionary stringValueForKey:@"isPartner"]isEqualToString:@"0"]?YES:NO;
    self.isNewGoods          = [userCenterDictionary stringValueForKey:@"isNewGoods"];
    self.isNewVideo          = [userCenterDictionary stringValueForKey:@"isNewVideo"];
    
    self.isBindAlipay           = [[userCenterDictionary stringValueForKey:@"isBindAlipay"]isEqualToString:@"Y"]?YES:NO;
    self.alipayName          = [userCenterDictionary stringValueForKey:@"alipayName"];
    self.alipayCode          = [userCenterDictionary stringValueForKey:@"alipayCode"];
    
    if (!self.isOpenJyh && [[userCenterDictionary stringValueForKey:@"isOpenJyh"]isEqualToString:@"0"]) {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"isOpenJyhNotification" object:nil];
    }
    
    self.isOpenJyh           = [[userCenterDictionary stringValueForKey:@"isOpenJyh"]isEqualToString:@"0"]?YES:NO;
    
    self.userNameStar        = [NSString stringWithFormat:@"%@****%@",[[userCenterDictionary stringValueForKey:@"userName"] substringToIndex:3],[[userCenterDictionary stringValueForKey:@"userName"] substringFromIndex:7]];
    
}

- (void)clearAccountMsg{
    self.userName                   = @"";
    self.userNameStar               = @"";
    self.headPortrait               = @"";
    self.businessWechat             = @"";
    self.levelId                    = @"";
    self.vipLevel                    = @"";
    self.levelImagePath             = @"";
    self.levelName                  = @"";
    self.nickName                   = @"";
    self.registerDate               = @"";
    self.shareCode                  = @"";
    self.upUserName                 = @"";
    self.userCode                   = @"";
    self.isPartner                  = NO;
    self.isOpenJyh                  = NO;
    self.isNeedToJyh                = NO;
    self.jyhGoodsId                 = @"";
    self.jyhGoodsGroupId            = @"";
    self.isBindAlipay               = NO;
    self.alipayName                 = @"";
    self.alipayCode                 = @"";
    self.appOpenId                  = @"";
}

#pragma mark - 解析地址
-(void)parseDataWithDict{
    NSDictionary  *addressData = [[NSUserDefaults standardUserDefaults]objectForKey:@"provAndCity"];
    
    NSMutableArray *provinceArr     = [[NSMutableArray alloc]init];
    NSMutableArray *cityDataArr     = [[NSMutableArray alloc]init];
    NSMutableArray *areaDataArr     = [[NSMutableArray alloc]init];
    for (NSDictionary *dict in [addressData arrayValueForKey:@"prov"]) {
        WHPickerAddressModel *model = [[WHPickerAddressModel alloc]init];
        model.pid = [dict stringValueForKey:@"provCd"];
        model.name = [dict stringValueForKey:@"provNm"];
        [provinceArr addObject:model];
    }
    
    NSMutableArray *cityArr = [NSMutableArray arrayWithArray:[addressData arrayValueForKey:@"city"]];
    for (WHPickerAddressModel *provModel in provinceArr) {
        NSMutableArray *cityTempArr = [[NSMutableArray alloc]init];
        for (NSDictionary *cityDict in cityArr) {
            if ([provModel.pid isEqualToString:[cityDict stringValueForKey:@"fCd"]]) {//为省对应的市
                WHPickerAddressModel *model = [[WHPickerAddressModel alloc]init];
                model.pid = [cityDict stringValueForKey:@"cityCd"];
                model.name = [cityDict stringValueForKey:@"cityNm"];
                [cityTempArr addObject:model];
            }
        }
        [cityDataArr addObject:cityTempArr];
    }
    
    for (NSArray *ProvCityArr in cityDataArr) {//ProvCityArr 省份下所有的城市
        NSMutableArray *areaCityTemp = [[NSMutableArray alloc]init];
        for (WHPickerAddressModel *cityModel in ProvCityArr) {//cityDic 每个城市的信息
            NSMutableArray *areaTempArr = [[NSMutableArray alloc]init];
            for (NSDictionary *areaDict in cityArr) {
                if ([cityModel.pid isEqualToString:[areaDict stringValueForKey:@"fCd"]]) {
                    WHPickerAddressModel *model = [[WHPickerAddressModel alloc]init];
                    model.pid = [areaDict stringValueForKey:@"cityCd"];
                    model.name = [areaDict stringValueForKey:@"cityNm"];
                    [areaTempArr addObject:model];
                }
            }
            [areaCityTemp addObject:areaTempArr];
        }
        [areaDataArr addObject:areaCityTemp];
    }
    
    self.addressProvinceArr = provinceArr;
    self.addressCityArr = cityDataArr;
    self.addressAreaArr = areaDataArr;
}

- (void)updateUserConfig:(NSDictionary *)userConfigDict{
    self.withDrawAmt = [userConfigDict stringValueForKey:@"withdrawAmt"];
    self.withDrawCnlId = [userConfigDict stringValueForKey:@"cmmCnlConfId"];
    self.withDrawTimeEnd = [userConfigDict stringValueForKey:@"endTime"];
    self.withDrawTimeStart = [userConfigDict stringValueForKey:@"startTime"];
    self.withDrawMinMoney = [userConfigDict stringValueForKey:@"minMoney"];
    self.withDrawMaxMoney = [userConfigDict stringValueForKey:@"maxMoney"];
    self.withDrawEnable = [[userConfigDict stringValueForKey:@"enableStatus"] isEqualToString:@"1"]?YES:NO;
    self.drawAmt             = [userConfigDict stringValueForKey:@"drawAmt"];
}

- (NSString *)userName{
    return _userName?_userName:@"";
}
- (NSString *)jyhGoodsId{
    return _jyhGoodsId?_jyhGoodsId:@"";
}
- (NSString *)jyhGoodsGroupId{
    return _jyhGoodsGroupId?_jyhGoodsGroupId:@"";
}
- (NSString *)userNameStar{
    return _userNameStar?_userNameStar:@"";
}
- (NSString *)upShareCode{
    return _upShareCode?_upShareCode:@"";
}
- (NSString *)upShareCodeTemp{
    return _upShareCodeTemp?_upShareCodeTemp:@"";
}
- (NSString *)alipayCode{
    return _alipayCode?_alipayCode:@"";
}
- (NSString *)alipayName{
    return _alipayName?_alipayName:@"";
}

- (NSString *)businessWechat{
    return _businessWechat?_businessWechat:@"";
}
- (NSString *)headPortrait{
    return _headPortrait?_headPortrait:@"";
}
- (NSString *)levelId{
    return _levelId?_levelId:@"0";
}
- (NSString *)vipLevel{
    return _vipLevel?_vipLevel:@"NORMAL";
}
- (NSString *)levelImagePath{
    return _levelImagePath?_levelImagePath:@"";
}
- (NSString *)levelName{
    return _levelName?_levelName:@"";
}
- (NSString *)nickName{
    return _nickName?_nickName:@"";
}
- (NSString *)registerDate{
    return _registerDate?_registerDate:@"";
}
- (NSString *)shareCode{
    return _shareCode?_shareCode:@"";
}
- (NSString *)drawAmt{
    return _drawAmt?_drawAmt:@"0";
}
- (NSString *)refillCardAvailableBalance{
    return _refillCardAvailableBalance?_refillCardAvailableBalance:@"0";
}
- (NSString *)accountBalance{
    return _accountBalance?_accountBalance:@"0";
}
- (NSString *)upUserName{
    return _upUserName?_upUserName:@"";
}
- (NSString *)userCode{
    return _userCode?_userCode:@"";
}
- (NSString *)wechatUnionId{
    return _wechatUnionId?_wechatUnionId:@"";
}
- (NSString *)wechatOpenId{
    return _wechatOpenId?_wechatOpenId:@"";
}
- (NSString *)wechatSex{
    return _wechatSex?_wechatSex:@"";
}
- (NSString *)wechatNickName{
    return _wechatNickName?_wechatNickName:@"";
}
- (NSString *)wechatHeadimgurl{
    return _wechatHeadimgurl?_wechatHeadimgurl:@"";
}
- (NSString *)wechatNo{
    return _wechatNo?_wechatNo:@"";
}
- (NSArray *)addressProvinceArr{
    return _addressProvinceArr?_addressProvinceArr:@[];
}
- (NSArray *)addressCityArr{
    return _addressCityArr?_addressCityArr:@[];
}
- (NSArray *)addressAreaArr{
    return _addressAreaArr?_addressAreaArr:@[];
}
- (NSString *)withDrawMinMoney{
    return _withDrawMinMoney?_withDrawMinMoney:@"";
}
- (NSString *)withDrawMaxMoney{
    return _withDrawMaxMoney?_withDrawMaxMoney:@"";
}
- (NSString *)withDrawTimeStart{
    return _withDrawTimeStart?_withDrawTimeStart:@"";
}
- (NSString *)withDrawTimeEnd{
    return _withDrawTimeEnd?_withDrawTimeEnd:@"";
}
- (NSString *)withDrawAmt{
    return _withDrawAmt?_withDrawAmt:@"";
}
- (NSString *)withDrawCnlId{
    return _withDrawCnlId?_withDrawCnlId:@"";
}

- (NSString *)appOpenId{
    return _appOpenId?_appOpenId:@"";
}
@end
